print "<b>Please create the following table for testing:</b></p>$createtab</p>";
return;
} else {
$db->debug = 1;
$e = error_reporting(E_ALL-E_WARNING);
$db->Execute($createtab);
error_reporting($e);
}
}
$rs = &$db->Execute("delete from ADOXYZ"); // some ODBC drivers will fail the drop so we delete
if ($rs) {
if(! $rs->EOF) print "<b>Error: </b>RecordSet returned by Execute('delete...') should show EOF</p>";
$rs->Close();
} else print "err=".$db->ErrorMsg();
print "<p>Test select on empty table, FetchField when EOF, and GetInsertSQL</p>";
$rs = &$db->Execute("select id,firstname from ADOXYZ where id=9999");
if ($rs && !$rs->EOF) print "<b>Error: </b>RecordSet returned by Execute(select...') on empty table should show EOF</p>";
if ($rs->EOF && (($ox = $rs->FetchField(0)) && !empty($ox->name))) {
$record['id'] = 99;
$record['firstname'] = 'John';
$sql = $db->GetInsertSQL($rs, $record);
if (strtoupper($sql) != strtoupper("INSERT INTO ADOXYZ ( id, firstname ) VALUES ( 99, 'John' )")) Err("GetInsertSQL does not work on empty table: $sql");
} else {
Err("FetchField does not work on empty recordset, meaning GetInsertSQL will fail...");
}
if ($rs) $rs->Close();
flush();
//$db->debug=true;
print "<p>Testing Commit: ";
$time = $db->DBDate(time());
if (!$db->BeginTrans()) {
print '<b>Transactions not supported</b></p>';
if ($db->hasTransactions) Err("hasTransactions should be false");
} else { /* COMMIT */
if (!$db->hasTransactions) Err("hasTransactions should be true");
if ($db->transCnt != 1) Err("Invalid transCnt = $db->transCnt (should be 1)");
$rs = $db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (99,'Should Not','Exist (Commit)',$time)");
if ($rs && $db->CommitTrans()) {
$rs->Close();
$rs = &$db->Execute("select * from ADOXYZ where id=99");
if ($rs === false || $rs->EOF) {
print '<b>Data not saved</b></p>';
$rs = &$db->Execute("select * from ADOXYZ where id=99");
print_r($rs);
die();
} else print 'OK</p>';
if ($rs) $rs->Close();
} else {
if (!$rs) {
print "<b>Insert failed</b></p>";
$db->RollbackTrans();
} else print "<b>Commit failed</b></p>";
}
if ($db->transCnt != 0) Err("Invalid transCnt = $db->transCnt (should be 0)");
/* ROLLBACK */
if (!$db->BeginTrans()) print "<p><b>Error in BeginTrans</b>()</p>";
print "<p>Testing Rollback: ";
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values (100,'Should Not','Exist (Rollback)',$time)");
if ($db->RollbackTrans()) {
$rs = $db->Execute("select * from ADOXYZ where id=100");
if ($rs && !$rs->EOF) print '<b>Fail: Data should rollback</b></p>';
else print 'OK</p>';
if ($rs) $rs->Close();
} else
print "<b>Commit failed</b></p>";
$rs = &$db->Execute('delete from ADOXYZ where id>50');
if ($rs) $rs->Close();
if ($db->transCnt != 0) Err("Invalid transCnt = $db->transCnt (should be 0)");
}
if (1) {
print "<p>Testing MetaDatabases()</p>";
print_r( $db->MetaDatabases());
print "<p>Testing MetaTables() and MetaColumns()</p>";
$a = $db->MetaTables();
if ($a===false) print "<b>MetaTables not supported</b></p>";
else {
print "Array of tables and views: ";
foreach($a as $v) print " ($v) ";
print '</p>';
}
$a = $db->MetaTables('VIEW');
if ($a===false) print "<b>MetaTables not supported (views)</b></p>";
else {
print "Array of views: ";
foreach($a as $v) print " ($v) ";
print '</p>';
}
$a = $db->MetaTables(false,false,'aDo%');
if ($a===false) print "<b>MetaTables not supported (mask)</b></p>";
else {
print "Array of ado%: ";
foreach($a as $v) print " ($v) ";
print '</p>';
}
$a = $db->MetaTables('TABLE');
if ($a===false) print "<b>MetaTables not supported</b></p>";
else {
print "Array of tables: ";
foreach($a as $v) print " ($v) ";
print '</p>';
}
$db->debug=0;
$rez = $db->MetaColumns("NOSUCHTABLEHERE");
if ($rez !== false) {
Err("MetaColumns error handling failed");
var_dump($rez);
}
$db->debug=1;
$a = $db->MetaColumns('ADOXYZ');
if ($a===false) print "<b>MetaColumns not supported</b></p>";
else {
print "<p>Columns of ADOXYZ: <font size=1><br>";
foreach($a as $v) {print_r($v); echo "<br>";}
echo "</font>";
}
print "<p>Testing MetaIndexes</p>";
$a = $db->MetaIndexes(('ADOXYZ'),true);
if ($a===false) print "<b>MetaIndexes not supported</b></p>";